home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / groupObjectsByName.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  125 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Jun 20, 1997
  22. //<doc>
  23. //<name groupObjectsByName>
  24. //<owner "Alias|Wavefront Unsupported">
  25. //
  26. //<synopsis>
  27. //        string[] groupObjectsByName( string $objectList[], string $token )
  28. //
  29. //<description>
  30. //        Given a list of strings, this procedure groups the strings into
  31. //        lists with the same object.
  32. //
  33. //<flags>
  34. //        string[]    $objectList List of objects to be grouped
  35. //        string        $token    Seperator at which the object grouping is defined
  36. //
  37. //<returns>
  38. //        string[] : $objectList, grouped by types separated by $token
  39. //
  40. //<examples>
  41. //  string $objectList[] = { "curve1.cv[1]",
  42. //                           "curve1.u[0.3]",
  43. //                           "curve3.cv[2]",
  44. //                           "curve4.cv[0]",
  45. //                           "curve1.cv[0]" };
  46. //  groupObjectsByName($objectList, ".");
  47. //  // Result : { "curve1.cv[1] curve1.u[0.3] curve1.cv[0]",
  48. //                "curve3.cv[2]", "curve4.cv[0]" } //
  49. //
  50. //  // The token is the string that limits the object name.  Changing
  51. //  // the token gives different results.
  52. //  //
  53. //  groupObjectsByName($objectList, "[");
  54. //  // Result : { "curve1.cv[1] curve1.cv[0]", "curve1.u[0.3]",
  55. //                "curve3.cv[2]", "curve4.cv[0]" } //
  56. //
  57. //</doc>
  58. //
  59.  
  60. proc int foundObjectInList( string $name, string $listOfNames[] )
  61. //
  62. //    Description:
  63. //        This procedure returns true if the given name was found in the
  64. //        list of names.  WARNING: this is a slow algorithm and is not
  65. //        efficient when dealing with a long list of names.
  66. //
  67. {
  68.     int $index = -1;
  69.     int $foundName = false;
  70.     int $numNames = size( $listOfNames );
  71.     for( $i = 0; $i < $numNames; $i ++ )
  72.     {
  73.         if( $name == $listOfNames[$i] )
  74.         {
  75.             $foundName = true;
  76.             $index = $i;
  77.             return $index;
  78.         }
  79.     }
  80.  
  81.     return $index;    
  82. }
  83.  
  84. global proc string[] groupObjectsByName( string $objectList[], string $token )
  85. {
  86.     string $processedNames[];
  87.     string $argList[];
  88.     int $i;
  89.  
  90.     // for each object in objectList, try to group it with previous objects
  91.     //
  92.     int $numObjects = size($objectList);
  93.  
  94.     for( $i = 0; $i < $numObjects; $i ++ )
  95.     {
  96.         string $objectName[];
  97.         $numTokens = `tokenize $objectList[$i] $token $objectName`;
  98.  
  99.         if( $numTokens > 0 )
  100.         {
  101.             int $index = foundObjectInList( $objectName[0], $processedNames );
  102.             if( $index >= 0 )
  103.             {
  104.                 // Concatenate the string
  105.                 //
  106.                 $argList[$index] = $argList[$index] + " ";
  107.                 $argList[$index] = $argList[$index] + $objectList[$i];
  108.             }
  109.             else
  110.             {
  111.                 // Add this name to the $processedNames
  112.                 //
  113.                 int $processedNamesSize = size( $processedNames );
  114.                 $processedNames[$processedNamesSize] = $objectName[0];
  115.  
  116.                 // start a new arg string
  117.                 //
  118.                 int $argSize = size( $argList );
  119.                 $argList[$argSize] = $objectList[$i];
  120.             }
  121.         }
  122.     }
  123.     return $argList;
  124. }
  125.